import {Page} from '@/base/Page';
import {InfoSort} from '@/base/model/InfoSort';
import {getInfoSortList} from '@/base/api/InfoSortApi';
import {Info} from '@/base/model/Info';
import {deleteInfo} from '@/base/api/InfoApi';

export class ListBloc {
  paged: Page<InfoSort> = new Page<InfoSort>([], 0, 1, 1000, 0, []);
  loading = false;

  load(pageIndex: number, pageSize: number) {
    this.loading = true;
    return getInfoSortList({
      pageIndex,
      pageSize,
      sortDirection: 'ASC',
      sortProperties: ['sort']
    }).then(res => {
      this.paged = res.data;
      return res;
    }).finally(() => {
      this.loading = false;
    });
  }

  removeItem(dateItem: Info) {
    this.loading = true;
    return deleteInfo(dateItem.id)
      .finally(() => {
        this.loading = false;
      });
  }
}
